import {createRouter, createWebHistory} from 'vue-router'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            component: () => import('../views/login.vue'),
        },
        {
            path: '/index',
            name: 'layout',
            component: () => import('../layout/index.vue'),
            meta:{
                flag:true
            },
            children: [
                {
                    path: '/speech',
                    component: () => import('../views/speech.vue'),
                    meta:{
                        flag:false
                    },
                },
                {
                    path: '/video',
                    component: () => import('../views/camera.vue'),
                    meta:{
                        flag:false
                    },
                },
                {
                    path: '/editWare',
                    component: () => import('../views/editWare.vue'),
                    meta:{
                        flag:false
                    },
                }, {

                    path: '/upload',
                    component: () => import('../views/uploadFile.vue'),
                    meta:{
                        flag:false
                    },
                },
                {
                    path: '/plan',
                    component: () => import('../views/personalcenter.vue'),
                    meta:{
                        flag:false
                    },
                },
                {
                    path: '/vrrs',
                    component: () => import('../views/vrrs.vue'),
                    meta:{
                        flag:false
                    },
                },
                {
                    path: '/detalis',
                    component: () => import('../views/details.vue'),
                    meta:{
                        flag:false
                    },
                },
                {
                    path: '/openWare',
                    component: () => import('../views/openWare.vue'),
                    meta:{
                        flag:false
                    },
                },
            ]
        },

    ],
})

// 路由守卫
router.beforeEach((to, from, next) => {
    if (to.path == "/") {
        return next(true)
    }
    const token = localStorage.getItem("token")
    if (!token) {
        return next("/")
    }
    return next(true)
})
export default router